package com.alex.tinyurl.service.store.db.dao;

import com.alex.tinyurl.service.store.db.entity.UrlMappingEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

@Mapper
//@ConditionalOnProperty(prefix = "tinyurl", name = "store.strategy", havingValue = "db")
public interface UrlMappingEntityDao {

    @Insert(value = "insert into tiny_url_map(tiny_url,original_url) value(#{tinyUrl},#{originalUrl})")
    int add(UrlMappingEntity e);

    @Select(value = "select tiny_url,original_url from tiny_url_map where tiny_url=#{tinyUrl}")
    UrlMappingEntity getByTinyUrl(String tinyUrl);

    @Select(value = "select tiny_url,original_url from tiny_url_map where original_url=#{originalUrl} ")
    UrlMappingEntity getByOriginalUrl(String originalUrl);

}
